package com.kgcx.system.service;

import com.github.pagehelper.PageHelper;
import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.domain.BaseDomain;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.system.domain.OaLog;
import com.kgcx.system.mapper.OaLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 吴刚林
 * @date 2017/11/20
 */
@Service
public class OaLogService {

    @Autowired
    private OaLogMapper oaLogMapper;


    public OaLog getOaLog(Long kid) {
        return oaLogMapper.selectByPrimaryKey(kid);

    }

    public List<OaLog> getOaLogList(RequestData rd) {
        PageUtils.page(rd);
        PageHelper.orderBy(rd.getOrderBy());
        return oaLogMapper.selectActive(BaseDomain.buildSelectDomain(rd, OaLog.class));

    }

    @Transactional(rollbackFor = Exception.class)
    public void addOaLog(OaLog oaLog) {
        oaLogMapper.insertSelective(oaLog);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateOaLog(OaLog oaLog) {
        oaLogMapper.updateByPrimaryKeySelective(oaLog);

    }

    @Transactional(rollbackFor = Exception.class)
    public void removeOaLog(Long kid) {
        OaLog oaLog = new OaLog();
        oaLog.setKid(kid);
        oaLog.setStatus(Cons.COMMON_STATUS_DELETE);
        oaLogMapper.updateByPrimaryKeySelective(oaLog);

    }
}
